package com.winhxd.b2c.common.feign.store;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.constant.ServiceName;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.store.condition.*;
import com.winhxd.b2c.common.domain.store.model.StoreUserInfo;
import com.winhxd.b2c.common.domain.store.vo.StoreInfoVO;
import com.winhxd.b2c.common.domain.store.vo.StoreUserInfoVO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * @author zhaoyanbiao
 * @Description: 门店用户管理
 * @date 2019年1月8日20:00:46
 */
@FeignClient(value = ServiceName.STORE_SERVICE, fallbackFactory = StoreUserInfoClientFallBack.class)
public interface StoreUserInfoClient {
    /**
     * 保存门店用户信息
     * @param storeUserInfoCondition
     * @return
     */
    @RequestMapping(value = "/store/1080/v1/saveStoreUserInfo", method = RequestMethod.POST)
    ResponseResult<StoreUserInfo> saveStoreUserInfo(@RequestBody StoreUserInfoCondition storeUserInfoCondition);

    /**
     * 通过条件查询门店的相关信息
     * @param condition
     * @return
     */
    @RequestMapping(value = "/store/1081/v1/selectStoreUserInfo", method = RequestMethod.POST)
    ResponseResult<List<StoreUserInfoVO>> findStoreUserInfo(@RequestBody StoreInfoCondition condition);

    /**
     * 查询店铺列表
     * @param condition
     * @return
     */
    @RequestMapping(value = "/store/1082/v1/selectStoreList", method = RequestMethod.POST)
    ResponseResult<PagedList<StoreInfoVO>> findStoreList(@RequestBody StoreInfoCondition condition);

    /**
     * 修改门店信息
     * @param storeInfoStatusCondition
     * @return
     */
    @RequestMapping(value = "/store/1083/v1/modifyStoreStatus", method = RequestMethod.POST)
    ResponseResult<Boolean> modifyStoreUserInfo(@RequestBody  StoreUserInfoCondition storeInfoStatusCondition);

}
@Component
class StoreUserInfoClientFallBack implements StoreUserInfoClient, FallbackFactory<StoreUserInfoClient> {
    Logger logger = LoggerFactory.getLogger(StoreUserInfoClientFallBack.class);
    Throwable throwable;

    @Override
    public StoreUserInfoClient create(Throwable throwable) {
        this.throwable = throwable;
        return new StoreUserInfoClientFallBack();
    }

    @Override
    public ResponseResult<StoreUserInfo> saveStoreUserInfo(StoreUserInfoCondition storeUserInfoCondition) {
        logger.error("StoreUserInfoClientFallBack -> saveStoreUserInfo{}", throwable.getMessage());
        return new ResponseResult<StoreUserInfo>(BusinessCode.CODE_1001);
    }

    @Override
    public ResponseResult<List<StoreUserInfoVO>> findStoreUserInfo(StoreInfoCondition condition) {
        logger.error("StoreUserInfoClientFallBack -> findStoreUserInfo{}", throwable.getMessage());
        return new ResponseResult<List<StoreUserInfoVO>>(BusinessCode.CODE_1001);
    }

    @Override
    public ResponseResult<PagedList<StoreInfoVO>> findStoreList(StoreInfoCondition condition) {
        logger.error("StoreUserInfoClientFallBack -> selectStoreList{}", throwable.getMessage());
        return new ResponseResult<PagedList<StoreInfoVO>>(BusinessCode.CODE_1001);
    }

    @Override
    public ResponseResult<Boolean> modifyStoreUserInfo(StoreUserInfoCondition storeInfoStatusCondition) {
        logger.error("StoreUserInfoClientFallBack -> modifyStoreUserInfo{}", throwable.getMessage());
        return new ResponseResult<Boolean>(BusinessCode.CODE_1001);
    }
}